package com.example.user.controller;

import com.example.common.core.constants.HttpConstants;
import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.vo.LoginUserVO;
import com.example.user.domain.teacher.dto.TeacherLoginDTO;
import com.example.user.domain.teacher.dto.TeacherSaveDTO;
import com.example.user.domain.teacher.vo.TeacherDetailVO;
import com.example.user.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher")
public class TeacherController extends BaseController {

    @Autowired
    private ITeacherService teacherService;


    @PostMapping("/login")
    public R<String> login(@RequestBody TeacherLoginDTO teacherLoginDTO) {
        return teacherService.login(teacherLoginDTO.getEmail(),teacherLoginDTO.getPassword());
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return teacherService.info(token);
    }

    @GetMapping("/detail")
    public R<TeacherDetailVO> detail(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return teacherService.detail(token);
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody TeacherSaveDTO teacherEditDTO) {
        return toR(teacherService.edit(teacherEditDTO));
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toR(teacherService.logout(token));
    }

    @PutMapping("/head-image/update")
    public R<Void> updateHeadImage(@RequestBody TeacherSaveDTO teacherUpdateDTO) {
        return toR(teacherService.updateHeadImage(teacherUpdateDTO.getHeadImage()));
    }
}